1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.webphotos.model;
17
18 import java.util.Collection;
19 import java.util.Date;
20 import java.util.HashSet;
21 import java.util.Iterator;
22
23
24
25
26
27 public class AlbumVOBuilder {
28
29 private String nmalbum;
30 private String descricao;
31 private Date dtInsercao;
32 private CategoryVO categoriasVO;
33 private HashSet<PhotoVO> photoVOs;
34 private Integer key;
35
36 AlbumVOBuilder() {
37 photoVOs = new HashSet<PhotoVO>();
38 key = 0;
39 }
40
41 AlbumVOBuilder(Integer key) {
42 this();
43 this.key = key;
44 }
45
46 public AlbumVOBuilder withAlbumName(String nmalbum) {
47 this.nmalbum = nmalbum;
48 return this;
49 }
50
51 public AlbumVOBuilder withDescription(String descricao) {
52 this.descricao = descricao;
53 return this;
54 }
55
56 public AlbumVOBuilder withCreationDate(Date dtInsercao) {
57 this.dtInsercao = dtInsercao;
58 return this;
59 }
60
61 public AlbumVOBuilder withCategory(CategoryVO categoriasVO) {
62 this.categoriasVO = categoriasVO;
63 return this;
64 }
65
66 public AlbumVOBuilder withPhoto(PhotoVO photoVO) {
67 this.photoVOs.add(photoVO);
68 return this;
69 }
70
71 public AlbumVOBuilder withPhotos(Collection<PhotoVO> photoVOs) {
72 this.photoVOs.addAll(photoVOs);
73 return this;
74 }
75
76 public AlbumVO build() {
77 final AlbumVO albumVO = (key > 0 ?
78 new AlbumVO(key, nmalbum, descricao, dtInsercao, categoriasVO, photoVOs) :
79 new AlbumVO(nmalbum, descricao, dtInsercao, categoriasVO, photoVOs));
80 for (Iterator<PhotoVO> it = photoVOs.iterator(); it.hasNext();) {
81 PhotoVO photoVO = it.next();
82 photoVO.setAlbum(albumVO);
83 }
84 return albumVO;
85 }
86
87 }